home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / winsock / ircii2-6.zip / SRC\IRCII-2.6\SOURCE\INPUT.C < prev    next >
C/C++ Source or Header  |  1995-01-02  |  20KB  |  793 lines

  1. /*
  2.  * input.c: does the actual input line stuff... keeps the appropriate stuff
  3.  * on the input line, handles insert/delete of characters/words... the whole
  4.  * ball o wax 
  5.  *
  6.  *
  7.  * Written By Michael Sandrof
  8.  *
  9.  * Copyright(c) 1990 
  10.  *
  11.  * See the COPYRIGHT file, or do a HELP IRCII COPYRIGHT 
  12.  */
  13.  
  14. #ifndef lint
  15. static    char    rcsid[] = "@(#)$Id: input.c,v 1.9 1994/07/03 08:23:47 mrg Stab $";
  16. #endif
  17.  
  18. #include "irc.h"
  19.  
  20. #include "input.h"
  21. #include "term.h"
  22. #include "alias.h"
  23. #include "vars.h"
  24. #include "ircaux.h"
  25. #include "window.h"
  26. #include "screen.h"
  27. #include "exec.h"
  28.  
  29. #define WIDTH 10
  30.  
  31. /* input_prompt: contains the current, unexpanded input prompt */
  32. static    char    *input_prompt = (char *) 0;
  33.  
  34. /* input_line: the actual screen line where the input goes */
  35. static    int    input_line;
  36.  
  37. /* str_start: position in buffer of first visible character in the input line */
  38. static    int    str_start = 0;
  39.  
  40. /*
  41.  * upper_mark and lower_mark: marks the upper and lower positions in the
  42.  * input buffer which will cause the input display to switch to the next or
  43.  * previous bunch of text 
  44.  */
  45. static    int    lower_mark;
  46. static    int    upper_mark;
  47.  
  48. /* zone: the amount of editable visible text on the screen */
  49. static    int    zone;
  50.  
  51. /* cursor: position of the cursor in the input line on the screen */
  52. static    int    cursor = 0;
  53.  
  54. /* cursor_to_input: move the cursor to the input line, if not there already */
  55. void
  56. cursor_to_input()
  57. {
  58.     Screen *old_current_screen;
  59.  
  60.     old_current_screen = current_screen;
  61.     for (current_screen = screen_list; current_screen;
  62.             current_screen = current_screen->next)
  63.     {
  64.         if (current_screen->alive && is_cursor_in_display())
  65.         {
  66.             term_move_cursor(cursor, input_line);
  67.             cursor_not_in_display();
  68.             term_flush();
  69.         }
  70.     }
  71.     set_current_screen(old_current_screen);
  72. }
  73.  
  74. /*
  75.  * update_input: does varying amount of updating on the input line depending
  76.  * upon the position of the cursor and the update flag.  If the cursor has
  77.  * move toward one of the edge boundaries on the screen, update_cursor()
  78.  * flips the input line to the next (previous) line of text. The update flag
  79.  * may be: 
  80.  *
  81.  * NO_UPDATE - only do the above bounds checking. 
  82.  *
  83.  * UPDATE_JUST_CURSOR - do bounds checking and position cursor where is should
  84.  * be. 
  85.  *
  86.  * UPDATE_FROM_CURSOR - does all of the above, and makes sure everything from
  87.  * the cursor to the right edge of the screen is current (by redrawing it). 
  88.  *
  89.  * UPDATE_ALL - redraws the entire line 
  90.  */
  91. void
  92. update_input(update)
  93.     int    update;
  94. {
  95.     int    old_start;
  96.     static    int    co = 0,
  97.             li = 0;
  98.     char    *ptr;
  99.     int    len,
  100.         free_it = 1,
  101.         cnt,
  102.         max;
  103.     char    *prompt;
  104.  
  105.     if (dumb)
  106.         return;
  107.     cursor_to_input();
  108.     if (current_screen->promptlist)
  109.         prompt = current_screen->promptlist->prompt;
  110.     else
  111.         prompt = input_prompt;
  112.     if (prompt)
  113.     {
  114.         if (update != NO_UPDATE)
  115.         {
  116.             char    *inp_ptr = (char *) 0;
  117.             int    args_used;    /* this isn't used here but is
  118.                          * passed to expand_alias()
  119.                          */
  120. #ifndef _Windows
  121.             if (is_process(get_target_by_refnum(0)))
  122.             {
  123.                 ptr = (char *)get_prompt_by_refnum(0);
  124.                 free_it = 0;
  125.             }
  126.             else
  127. #endif
  128.                 ptr = expand_alias((char *) 0, prompt, empty_string, &args_used, NULL);
  129.             if (*ptr && ((my_strnicmp(ptr, "Password:", 9) == 0) || (my_strnicmp(ptr, "Operator Password:",18) == 0) ||
  130.                     (my_strnicmp(ptr, "Server Password:", 16) == 0)))
  131.                 term_echo(0);
  132.             else
  133.                 term_echo(1);
  134.             len = strlen(ptr);
  135.             if (strncmp(ptr, current_screen->input_buffer, len) || !len)
  136.             {
  137.                 malloc_strcpy(&inp_ptr, current_screen->input_buffer + current_screen->buffer_min_pos);
  138.                 strmcpy(current_screen->input_buffer, ptr, INPUT_BUFFER_SIZE);
  139.                 current_screen->buffer_pos += (len - current_screen->buffer_min_pos);
  140.                 current_screen->buffer_min_pos = strlen(ptr);
  141.                 strmcat(current_screen->input_buffer, inp_ptr, INPUT_BUFFER_SIZE);
  142.                 new_free(&inp_ptr);
  143.                 update = UPDATE_ALL;
  144.             }
  145.             if (free_it)
  146.                 new_free(&ptr);
  147.         }
  148.     }
  149.     else
  150.         term_echo(1);
  151.     if ((li != LI) || (co != CO))
  152.     {
  153.         /* resized?  Keep it simple and reset everything */
  154.         input_line = LI - 1;
  155.         zone = CO - (WIDTH * 2);
  156.         lower_mark = WIDTH;
  157.         upper_mark = CO - WIDTH;
  158.         cursor = current_screen->buffer_min_pos;
  159.         current_screen->buffer_pos = current_screen->buffer_min_pos;
  160.         str_start = 0;
  161.         li = LI;
  162.         co = CO;
  163.     }
  164.     old_start = str_start;
  165.     while ((current_screen->buffer_pos < lower_mark) && lower_mark > WIDTH)
  166.     {
  167.         upper_mark = lower_mark;
  168.         lower_mark -= zone;
  169.         str_start -= zone;
  170.     }
  171.     while (current_screen->buffer_pos >= upper_mark)
  172.     {
  173.         lower_mark = upper_mark;
  174.         upper_mark += zone;
  175.         str_start += zone;
  176.     }
  177.     cursor = current_screen->buffer_pos - str_start;
  178.     if ((old_start != str_start) || (update == UPDATE_ALL))
  179.     {
  180.         term_move_cursor(0, input_line);
  181.         if ((str_start == 0) && (current_screen->buffer_min_pos > 0))
  182.         {
  183.             int    echo;
  184.  
  185.             echo = term_echo(1);
  186.             if (current_screen->buffer_min_pos > (CO - WIDTH))
  187.                 len = CO - WIDTH - 1;
  188.             else
  189.                 len = current_screen->buffer_min_pos;
  190.             cnt = term_puts(&(current_screen->input_buffer[
  191.                 str_start]), len);
  192.             term_echo(echo);
  193.             cnt += term_puts(&(current_screen->input_buffer[
  194.                 str_start + len]), CO - len);
  195.         }
  196.         else
  197.             cnt = term_puts(&(current_screen->input_buffer[
  198.                 str_start]), CO);
  199.         if (term_clear_to_eol())
  200.             term_space_erase(cnt);
  201.         term_move_cursor(cursor, input_line);
  202.     }
  203.     else if (update == UPDATE_FROM_CURSOR)
  204.     {
  205.         term_move_cursor(cursor, input_line);
  206.         cnt = cursor;
  207.         max = CO - (current_screen->buffer_pos - str_start);
  208.         if ((len = strlen(&(current_screen->input_buffer[
  209.                 current_screen->buffer_pos]))) > max)
  210.             len = max;
  211.         cnt += term_puts(&(current_screen->input_buffer[
  212.             current_screen->buffer_pos]), len);
  213.         if (term_clear_to_eol())
  214.             term_space_erase(cnt);
  215.         term_move_cursor(cursor, input_line);
  216.     }
  217.     else if (update == UPDATE_JUST_CURSOR)
  218.         term_move_cursor(cursor, input_line);
  219.     term_flush();
  220. }
  221.  
  222. void
  223. refresh_inputline()
  224. {
  225.     update_input(UPDATE_ALL);
  226. }
  227.  
  228. void
  229. change_input_prompt(direction)
  230.     int    direction;
  231. {
  232.     if (!current_screen->promptlist)
  233.     {
  234.         strcpy(current_screen->input_buffer,
  235.                 current_screen->saved_input_buffer);
  236.         current_screen->buffer_pos =
  237.                 current_screen->saved_buffer_pos;
  238.         current_screen->buffer_min_pos =
  239.                 current_screen->saved_min_buffer_pos;
  240.         update_input(UPDATE_ALL);
  241.     }
  242.     else if (direction == -1)
  243.     {
  244.         update_input(UPDATE_ALL);
  245.     }
  246.     else if (!current_screen->promptlist->next)
  247.     {
  248.         strcpy(current_screen->saved_input_buffer,
  249.                 current_screen->input_buffer);
  250.         current_screen->saved_buffer_pos =
  251.                 current_screen->buffer_pos;
  252.         current_screen->saved_min_buffer_pos =
  253.                 current_screen->buffer_min_pos;
  254.         *current_screen->input_buffer = '\0';
  255.         current_screen->buffer_pos =
  256.                 current_screen->buffer_min_pos = 0;
  257.         update_input(UPDATE_ALL);
  258.     }
  259. }
  260.  
  261. /* input_move_cursor: moves the cursor left or right... got it? */
  262. void
  263. input_move_cursor(dir)
  264.     int    dir;
  265. {
  266.     cursor_to_input();
  267.     if (dir)
  268.     {
  269.         if (current_screen->input_buffer[current_screen->buffer_pos])
  270.         {
  271.             current_screen->buffer_pos++;
  272.             if (term_cursor_right())
  273.                 term_move_cursor(cursor + 1, input_line);
  274.         }
  275.     }
  276.     else
  277.     {
  278.         if (current_screen->buffer_pos > current_screen->buffer_min_pos)
  279.         {
  280.             current_screen->buffer_pos--;
  281.             if (term_cursor_left())
  282.                 term_move_cursor(cursor - 1, input_line);
  283.         }
  284.     }
  285.     update_input(NO_UPDATE);
  286. }
  287.  
  288. /*
  289.  * input_forward_word: move the input cursor forward one word in the input
  290.  * line 
  291.  */
  292. void
  293. input_forward_word()
  294. {
  295.     cursor_to_input();
  296.     while (
  297.       (isspace(current_screen->input_buffer[current_screen->buffer_pos]) ||
  298.       ispunct(current_screen->input_buffer[current_screen->buffer_pos])) &&
  299.       current_screen->input_buffer[current_screen->buffer_pos])
  300.         current_screen->buffer_pos++;
  301.     while
  302.      (!(ispunct(current_screen->input_buffer[current_screen->buffer_pos]) ||
  303.      isspace(current_screen->input_buffer[current_screen->buffer_pos])) &&
  304.      current_screen->input_buffer[current_screen->buffer_pos])
  305.         current_screen->buffer_pos++;
  306.     update_input(UPDATE_JUST_CURSOR);
  307. }
  308.  
  309. /* input_backward_word: move the cursor left on word in the input line */
  310. void
  311. input_backward_word()
  312. {
  313.     cursor_to_input();
  314.     while ((current_screen->buffer_pos > current_screen->buffer_min_pos) &&
  315.      (isspace(current_screen->input_buffer[current_screen->buffer_pos - 1])
  316.      ||
  317.      ispunct(current_screen->input_buffer[current_screen->buffer_pos - 1])))
  318.         current_screen->buffer_pos--;
  319.     while ((current_screen->buffer_pos > current_screen->buffer_min_pos) &&
  320.      !(ispunct(current_screen->input_buffer[current_screen->buffer_pos - 1])
  321.      ||
  322.      isspace(current_screen->input_buffer[current_screen->buffer_pos - 1])))
  323.         current_screen->buffer_pos--;
  324.     update_input(UPDATE_JUST_CURSOR);
  325. }
  326.  
  327. /* input_delete_character: deletes a character from the input line */
  328. void
  329. input_delete_character()
  330. {
  331.     cursor_to_input();
  332.     if (current_screen->input_buffer[current_screen->buffer_pos])
  333.     {
  334.         char    *ptr = (char *) 0;
  335.         int    pos;
  336.  
  337.         malloc_strcpy(&ptr,
  338.           &(current_screen->input_buffer[current_screen->buffer_pos
  339.           + 1]));
  340.         strcpy(&(current_screen->input_buffer[
  341.             current_screen->buffer_pos]), ptr);
  342.         new_free(&ptr);
  343.         if (term_delete())
  344.             update_input(UPDATE_FROM_CURSOR);
  345.         else
  346.         {
  347.             pos = str_start + CO - 1;
  348.             if (pos < strlen(current_screen->input_buffer))
  349.             {
  350.                 term_move_cursor(CO - 1, input_line);
  351.                 term_putchar(current_screen->input_buffer[pos]);
  352.                 term_move_cursor(cursor, input_line);
  353.             }
  354.             update_input(NO_UPDATE);
  355.         }
  356.     }
  357. }
  358.  
  359. /* input_backspace: does a backspace in the input buffer */
  360. /*ARGSUSED*/
  361. void
  362. input_backspace(key, ptr)
  363.     char    *key;
  364.     void    (*ptr)();
  365. {
  366.     cursor_to_input();
  367.     if (current_screen->buffer_pos > current_screen->buffer_min_pos)
  368.     {
  369.         char    *ptr = (char *) 0;
  370.         int    pos;
  371.  
  372.         malloc_strcpy(&ptr,
  373.           &(current_screen->input_buffer[current_screen->buffer_pos]));
  374.         strcpy(&(current_screen->input_buffer[current_screen->buffer_pos
  375.             - 1]), ptr);
  376.         new_free(&ptr);
  377.         current_screen->buffer_pos--;
  378.         if (term_cursor_left())
  379.             term_move_cursor(cursor - 1, input_line);
  380.         if (current_screen->input_buffer[current_screen->buffer_pos])
  381.         {
  382.             if (term_delete())
  383.             {
  384.                 update_input(UPDATE_FROM_CURSOR);
  385.                 return;
  386.             }
  387.             else
  388.             {
  389.                 pos = str_start + CO - 1;
  390.                 if (pos < strlen(current_screen->input_buffer))
  391.                 {
  392.                     term_move_cursor(CO - 1, input_line);
  393.                 term_putchar(current_screen->input_buffer[pos]);
  394.                 }
  395.                 update_input(UPDATE_JUST_CURSOR);
  396.             }
  397.         }
  398.         else
  399.         {
  400.             term_putchar(' ');
  401.             if (term_cursor_left())
  402.                 term_move_cursor(cursor - 1, input_line);
  403.             update_input(NO_UPDATE);
  404.         }
  405.     }
  406. }
  407.  
  408. /*
  409.  * input_beginning_of_line: moves the input cursor to the first character in
  410.  * the input buffer 
  411.  */
  412. void
  413. input_beginning_of_line()
  414. {
  415.     cursor_to_input();
  416.     current_screen->buffer_pos = current_screen->buffer_min_pos;
  417.     update_input(UPDATE_JUST_CURSOR);
  418. }
  419.  
  420. /*
  421.  * input_end_of_line: moves the input cursor to the last character in the
  422.  * input buffer 
  423.  */
  424. void
  425. input_end_of_line()
  426. {
  427.     cursor_to_input();
  428.     current_screen->buffer_pos = strlen(current_screen->input_buffer);
  429.     update_input(UPDATE_JUST_CURSOR);
  430. }
  431.  
  432. /*
  433.  * input_delete_previous_word: deletes from the cursor backwards to the next
  434.  * space character. 
  435.  */
  436. void
  437. input_delete_previous_word()
  438. {
  439.     int    old_pos;
  440.     char    c;
  441.  
  442.     cursor_to_input();
  443.     old_pos = current_screen->buffer_pos;
  444.     while ((current_screen->buffer_pos > current_screen->buffer_min_pos) &&
  445.      (isspace(current_screen->input_buffer[current_screen->buffer_pos - 1])
  446.      ||
  447.      ispunct(current_screen->input_buffer[current_screen->buffer_pos - 1])))
  448.         current_screen->buffer_pos--;
  449.     while ((current_screen->buffer_pos > current_screen->buffer_min_pos) &&
  450.      !(ispunct(current_screen->input_buffer[current_screen->buffer_pos - 1])
  451.      ||
  452.      isspace(current_screen->input_buffer[current_screen->buffer_pos - 1])))
  453.         current_screen->buffer_pos--;
  454.     c = current_screen->input_buffer[old_pos];
  455.     current_screen->input_buffer[old_pos] = (char) 0;
  456.     malloc_strcpy(&cut_buffer,
  457.         &(current_screen->input_buffer[current_screen->buffer_pos]));
  458.     current_screen->input_buffer[old_pos] = c;
  459.     strcpy(&(current_screen->input_buffer[current_screen->buffer_pos]),
  460.         &(current_screen->input_buffer[old_pos]));
  461.     update_input(UPDATE_FROM_CURSOR);
  462. }
  463.  
  464. /*
  465.  * input_delete_next_word: deletes from the cursor to the end of the next
  466.  * word 
  467.  */
  468. void
  469. input_delete_next_word()
  470. {
  471.     int    pos;
  472.     char    *ptr = (char *) 0,
  473.         c;
  474.  
  475.     cursor_to_input();
  476.     pos = current_screen->buffer_pos;
  477.     while ((isspace(current_screen->input_buffer[pos]) ||
  478.         ispunct(current_screen->input_buffer[pos])) &&
  479.         current_screen->input_buffer[pos])
  480.         pos++;
  481.     while (!(ispunct(current_screen->input_buffer[pos]) ||
  482.         isspace(current_screen->input_buffer[pos])) &&
  483.         current_screen->input_buffer[pos])
  484.         pos++;
  485.     c = current_screen->input_buffer[pos];
  486.     current_screen->input_buffer[pos] = (char) 0;
  487.     malloc_strcpy(&cut_buffer,
  488.         &(current_screen->input_buffer[current_screen->buffer_pos]));
  489.     current_screen->input_buffer[pos] = c;
  490.     malloc_strcpy(&ptr, &(current_screen->input_buffer[pos]));
  491.     strcpy(&(current_screen->input_buffer[current_screen->buffer_pos]),            ptr);
  492.     new_free(&ptr);
  493.     update_input(UPDATE_FROM_CURSOR);
  494. }
  495.  
  496. /*
  497.  * input_add_character: adds the character c to the input buffer, repecting
  498.  * the current overwrite/insert mode status, etc 
  499.  */
  500. /*ARGSUSED*/
  501. void
  502. input_add_character(c, unused)
  503.     char    c;
  504.     char    *unused;
  505. {
  506.     int    display_flag = NO_UPDATE;
  507.  
  508.     cursor_to_input();
  509.     if (current_screen->buffer_pos < INPUT_BUFFER_SIZE)
  510.     {
  511.         if (get_int_var(INSERT_MODE_VAR))
  512.         {
  513.             if (current_screen->input_buffer[
  514.                     current_screen->buffer_pos])
  515.             {
  516.                 char    *ptr = (char *) 0;
  517.  
  518.                 malloc_strcpy(&ptr, &(
  519.                     current_screen->input_buffer[
  520.                     current_screen->buffer_pos]));
  521.                 current_screen->input_buffer[
  522.                     current_screen->buffer_pos] = c;
  523.                 current_screen->input_buffer[
  524.                     current_screen->buffer_pos + 1] =
  525.                     (char) 0;
  526.                 strmcat(current_screen->input_buffer, ptr,
  527.                     INPUT_BUFFER_SIZE);
  528.                 new_free(&ptr);
  529.                 if (term_insert(c))
  530.                 {
  531.                     term_putchar(c);
  532.                     if (current_screen->input_buffer[
  533.                         current_screen->buffer_pos + 1])
  534.                         display_flag = UPDATE_FROM_CURSOR;
  535.                     else
  536.                         display_flag = NO_UPDATE;
  537.                 }
  538.             }
  539.             else
  540.             {
  541.                 current_screen->input_buffer[
  542.                     current_screen->buffer_pos] = c;
  543.                 current_screen->input_buffer[
  544.                     current_screen->buffer_pos + 1] =
  545.                     (char) 0;
  546.                 term_putchar(c);
  547.             }
  548.         }
  549.         else
  550.         {
  551.             if (current_screen->input_buffer[
  552.                     current_screen->buffer_pos] == (char) 0)
  553.                 current_screen->input_buffer[
  554.                    current_screen->buffer_pos + 1] = (char) 0;
  555.             current_screen->input_buffer[current_screen->buffer_pos]
  556.                 = c;
  557.             term_putchar(c);
  558.         }
  559.         current_screen->buffer_pos++;
  560.         update_input(display_flag);
  561.     }
  562. }
  563.  
  564. #ifndef _Windows
  565. /*
  566.  * set_input: sets the input buffer to the given string, discarding whatever
  567.  * was in the input buffer before 
  568.  */
  569. void
  570. set_input(str)
  571.     char    *str;
  572. {
  573.     strmcpy(current_screen->input_buffer + current_screen->buffer_min_pos,
  574.         str, INPUT_BUFFER_SIZE - current_screen->buffer_min_pos);
  575.     current_screen->buffer_pos = strlen(current_screen->input_buffer);
  576. }
  577.  
  578. /*
  579.  * get_input: returns a pointer to the input buffer.  Changing this will
  580.  * actually change the input buffer.  This is a bad way to change the input
  581.  * buffer tho, cause no bounds checking won't be done 
  582.  */
  583. char    *
  584. get_input()
  585. {
  586.     return (&(current_screen->input_buffer[current_screen->buffer_min_pos]));
  587. }
  588. #endif
  589.  
  590. /* input_clear_to_eol: erases from the cursor to the end of the input buffer */
  591. void
  592. input_clear_to_eol()
  593. {
  594.     cursor_to_input();
  595.     malloc_strcpy(&cut_buffer,
  596.         &(current_screen->input_buffer[current_screen->buffer_pos]));
  597.     current_screen->input_buffer[current_screen->buffer_pos] = (char) 0;
  598.     if (term_clear_to_eol())
  599.     {
  600.         term_space_erase(cursor);
  601.         term_move_cursor(cursor, input_line);
  602.     }
  603.     update_input(NO_UPDATE);
  604. }
  605.  
  606. /*
  607.  * input_clear_to_bol: clears from the cursor to the beginning of the input
  608.  * buffer 
  609.  */
  610. void
  611. input_clear_to_bol()
  612. {
  613.     char    *ptr = (char *) 0;
  614.  
  615.     cursor_to_input();
  616.     malloc_strcpy(&cut_buffer,
  617.         &(current_screen->input_buffer[current_screen->buffer_min_pos]));
  618.     cut_buffer[current_screen->buffer_pos -
  619.         current_screen->buffer_min_pos] = (char) 0;
  620.     malloc_strcpy(&ptr,
  621.         &(current_screen->input_buffer[current_screen->buffer_pos]));
  622.     current_screen->input_buffer[current_screen->buffer_min_pos] =
  623.         (char) 0;
  624.     strmcat(current_screen->input_buffer, ptr, INPUT_BUFFER_SIZE);
  625.     new_free(&ptr);
  626.     current_screen->buffer_pos = current_screen->buffer_min_pos;
  627.     term_move_cursor(current_screen->buffer_min_pos, input_line);
  628.     if (term_clear_to_eol())
  629.     {
  630.         term_space_erase(current_screen->buffer_min_pos);
  631.         term_move_cursor(current_screen->buffer_min_pos, input_line);
  632.     }
  633.     update_input(UPDATE_FROM_CURSOR);
  634. }
  635.  
  636. /*
  637.  * input_clear_line: clears entire input line
  638.  */
  639. void
  640. input_clear_line()
  641. {
  642.     cursor_to_input();
  643.     malloc_strcpy(&cut_buffer, current_screen->input_buffer +
  644.         current_screen->buffer_min_pos);
  645.     current_screen->input_buffer[current_screen->buffer_min_pos] =
  646.         (char) 0;
  647.     current_screen->buffer_pos = current_screen->buffer_min_pos;
  648.     term_move_cursor(current_screen->buffer_min_pos, input_line);
  649.     if (term_clear_to_eol())
  650.     {
  651.         term_space_erase(current_screen->buffer_min_pos);
  652.         term_move_cursor(current_screen->buffer_min_pos, input_line);
  653.     }
  654.     update_input(NO_UPDATE);
  655. }
  656.  
  657. /*
  658.  * input_transpose_characters: swaps the positions of the two characters
  659.  * before the cursor position 
  660.  */
  661. void
  662. input_transpose_characters()
  663. {
  664.     cursor_to_input();
  665.     if (current_screen->buffer_pos > current_screen->buffer_min_pos &&
  666.         current_screen->input_buffer[current_screen->buffer_pos])
  667.     {
  668.         char    c1,
  669.             c2;
  670.  
  671.         c1 = current_screen->input_buffer[current_screen->buffer_pos];
  672.         c2 = current_screen->input_buffer[current_screen->buffer_pos] =
  673.                 current_screen->input_buffer[current_screen->buffer_pos - 1];
  674.         current_screen->input_buffer[current_screen->buffer_pos - 1]
  675.             = c1;
  676.         if (term_cursor_left())
  677.             term_move_cursor(cursor - 1, input_line);
  678.         term_putchar(c1);
  679.         term_putchar(c2);
  680.         if (term_cursor_left())
  681.             term_move_cursor(cursor - 1, input_line);
  682.         update_input(NO_UPDATE);
  683.     }
  684. }
  685.  
  686. /* init_input: initialized the input buffer by clearing it out */
  687. void
  688. init_input()
  689. {
  690.     *current_screen->input_buffer = (char) 0;
  691.     current_screen->buffer_pos = current_screen->buffer_min_pos;
  692. }
  693.  
  694. /*
  695.  * input_yank_cut_buffer: takes the contents of the cut buffer and inserts it
  696.  * into the input line 
  697.  */
  698. void
  699. input_yank_cut_buffer()
  700. {
  701.     char    *ptr = (char *) 0;
  702.  
  703.     if (cut_buffer)
  704.     {
  705.         malloc_strcpy(&ptr,
  706.            &(current_screen->input_buffer[current_screen->buffer_pos]));
  707.         current_screen->input_buffer[current_screen->buffer_pos] =
  708.             (char) 0;
  709.         strmcat(current_screen->input_buffer, cut_buffer,
  710.             INPUT_BUFFER_SIZE);
  711.         strmcat(current_screen->input_buffer, ptr, INPUT_BUFFER_SIZE);
  712.         new_free(&ptr);
  713.         update_input(UPDATE_FROM_CURSOR);
  714.         current_screen->buffer_pos += strlen(cut_buffer);
  715.         if (current_screen->buffer_pos > INPUT_BUFFER_SIZE)
  716.             current_screen->buffer_pos = INPUT_BUFFER_SIZE;
  717.         update_input(UPDATE_JUST_CURSOR);
  718.     }
  719. }
  720.  
  721. /* get_input_prompt: returns the current input_prompt */
  722. char    *
  723. get_input_prompt()
  724.     return (input_prompt); 
  725. }
  726.  
  727. /*
  728.  * set_input_prompt: sets a prompt that will be displayed in the input
  729.  * buffer.  This prompt cannot be backspaced over, etc.  It's a prompt.
  730.  * Setting the prompt to null uses no prompt 
  731.  */
  732. void
  733. set_input_prompt(prompt)
  734.     char    *prompt;
  735. {
  736.     if (prompt)
  737.     {
  738.         if (input_prompt && !strcmp (prompt, input_prompt))
  739.             return;
  740.         malloc_strcpy(&input_prompt, prompt);
  741.     }
  742.     else
  743.     {
  744.         if (!input_prompt)
  745.             return;
  746.         malloc_strcpy(&input_prompt, empty_string);
  747.     }
  748.     update_input(UPDATE_ALL);
  749. }
  750.  
  751. /*
  752.  * input_pause: prompt the user with a message then waits for a single
  753.  * keystroke before continuing.  The key hit is returned. 
  754.  *
  755.  * This function is NEVER to be called, once the inital irc_io()
  756.  * loop has been called from main().  Perhaps it would be better
  757.  * to just put this code at the only place it is called, and not
  758.  * have the function.  If you want an input_pause, use add_wait_prompt()
  759.  * with WAIT_PROMPT_KEY.
  760.  */
  761. char
  762. input_pause(msg)
  763.     char    *msg;
  764. {
  765.     char    *ptr = (char *) 0;
  766.     char    c;
  767.  
  768.     if (dumb)
  769.     {
  770.         puts(msg);
  771.         fflush(stdout);
  772.         if (use_input)
  773.             irc_io(&c, NULL, -1, 1);
  774.     }
  775.     else
  776.     {
  777.         malloc_strcpy(&ptr, get_input());
  778.         set_input(msg);
  779.         update_input(UPDATE_ALL);
  780.         irc_io(&c, NULL, -1, 1);
  781.         set_input(ptr);
  782.         update_input(UPDATE_ALL);
  783.         new_free(&ptr);
  784.     }
  785.     return (c);
  786. }
  787.  
  788. int    term_pause(void)
  789. {
  790.     return 0;
  791. }
  792.